package com.example.libraryapp.fragment.home;

import com.example.libraryapp.bean.BannerBean;
import com.example.libraryapp.bean.Book;
import com.example.libraryapp.bean.response.BaseResponse;
import com.example.libraryapp.network.base.BaseHttpHandler;
import com.example.libraryapp.network.base.BasePresenter;

import java.util.List;

/**
 * @author 伍凯铭
 * @since 2020/6/21
 */
public class HomePresenterIml extends BasePresenter<HomeContract.View> implements HomeContract.Presenter{

    @Override
    public void getBookByCondition(String condition) {
        super.doRequest(getRequestService().getByCondition(condition),new GetAllBookHandler());
    }

    @Override
    public void getBanner() {
        super.doRequest(getRequestService().getBanner(),new GetBannerHandler());
    }

    class GetAllBookHandler extends BaseHttpHandler<BaseResponse<List<Book>>> {

        GetAllBookHandler() {
            super(mView);
        }

        @Override
        public void onSuccess(BaseResponse<List<Book>> result) {
            if(mView != null) {
                mView.showContent();
                mView.showAllBook(result);
            }
        }
    }

    class GetBannerHandler extends BaseHttpHandler<BaseResponse<List<BannerBean>>> {

        GetBannerHandler() {
            super(mView);
        }

        @Override
        public void onSuccess(BaseResponse<List<BannerBean>> result) {
            if(mView != null) {
                mView.showContent();
                mView.showBanner(result);
            }
        }

    }
}
